package com.totcy.atom.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.totcy.atom.R;
import com.totcy.atom.bean.HeWeatherDailyForecast;
import com.totcy.atom.utils.glide.GlideUtil;
import com.totcy.atom.utils.weather.WeatherConvert;
import com.totcy.baselibrary.adapter.BaseRecyleAdapter;
import com.totcy.baselibrary.adapter.BaseViewHolder;
import com.totcy.baselibrary.utils.DateUtils;

import java.util.List;

/**
 * description: 3-7天气适配器
 * autour: Totcy
 * date: 2018/1/21 15:18
 * update: 2018/1/21
 */
public class DailyForecastAdapter extends BaseRecyleAdapter<HeWeatherDailyForecast> {

    public DailyForecastAdapter(Context mContext, List<HeWeatherDailyForecast> mDatas) {
        super(mContext, mDatas, R.layout.item_daily_forecast);
    }

    @Override
    protected void convert(Context mContext, BaseViewHolder holder, HeWeatherDailyForecast dailyForecast) {
        String dateText;
        long tomorrowTime = System.currentTimeMillis() + 3600 * 24 * 1000;
        if (DateUtils.getStrTime(System.currentTimeMillis(), DateUtils.YYYY_MM_DD).equals(dailyForecast.getDate())) {
            dateText = "今天";
        } else if (DateUtils.getStrTime(tomorrowTime, DateUtils.YYYY_MM_DD).equals(dailyForecast.getDate())) {
            dateText = "明天";
        } else {
            String[] arr = dailyForecast.getDate().split("-");
            if (arr.length > 2) {
                dateText = arr[1] + "-" + arr[2];
            } else {
                dateText = dailyForecast.getDate();
            }
        }

        holder.setText(R.id.tv_date, dateText);
        holder.setText(R.id.tv_itemWeather, dailyForecast.getCond_txt_d());
        holder.setText(R.id.tv_itemTmp, dailyForecast.getTmp_max() + "/" + dailyForecast.getTmp_min() + "℃");
        WeatherConvert.WeatherIconBean weatherIconBean = WeatherConvert.weatherCode2Local(dailyForecast.getCond_code_d());
        GlideUtil.loadImageNoPlaceholder(mContext, weatherIconBean.getIconRes(), (ImageView) holder.getView(R.id.iv_weatherIcon),true, R.drawable.weizhi);

        holder.setText(R.id.tv_itemWeatherNight, dailyForecast.getCond_txt_n());
        WeatherConvert.WeatherIconBean weatherIconBeanN = WeatherConvert.weatherCode2Local(dailyForecast.getCond_code_n());
        GlideUtil.loadImageNoPlaceholder(mContext, weatherIconBeanN.getIconRes(), (ImageView) holder.getView(R.id.iv_weatherIconNight),true, R.drawable.weizhi);
    }
}
